<?php

define('COOKIE_SECRET', 'pizW#iy:=7$\*2f/NPTp^$Mvl8|X{e~NpE":6J`(p9}Z/C:tA~dt`e.%l"I[0Ya}-H');
define('SIGN_ALGO', 'sha256');

class SignedCookie {
	
	function sign($salt, $data) {
		$ctx = hash_init(SIGN_ALGO);
		hash_update($ctx, $salt);
		hash_update($ctx, COOKIE_SECRET);
		hash_update($ctx, $data);
		$sign = hash_final($ctx);
		return $sign;
	}
	
	function verify($salt, $data, $sign) {
		$sign_expected = $this->sign($salt, $data);
		return ($sign_expected == $sign) ? true : false;
	}
}